﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace ClassicJukebox.View
{
    /// <summary>
    /// Interaction logic for MediaView.xaml
    /// </summary>
    public partial class MediaView : UserControl
    {
        public MediaView()
        {
            InitializeComponent();
        }

        #region Book hack too keep it in sync

        private ICollectionView albumsCollectionView;

        private void MediaView_Loaded(object sender, RoutedEventArgs e)
        {
            this.albumsCollectionView = CollectionViewSource.GetDefaultView(myBook.ItemsSource);
            this.albumsCollectionView.CurrentChanged += new EventHandler(this.MediaView_CurrentChanged);
            this.albumsCollectionView.CurrentChanging += new System.ComponentModel.CurrentChangingEventHandler(this.MediaView_CurrentChanging);
        }

        private int prePosition = -1;
        private void MediaView_CurrentChanging(object sender, System.ComponentModel.CurrentChangingEventArgs e)
        {
            this.prePosition = this.albumsCollectionView.CurrentPosition;
        }

        private void MediaView_CurrentChanged(object sender, EventArgs e)
        {
            if (this.prePosition > this.albumsCollectionView.CurrentPosition)
            {
                if (this.prePosition % 2 == 0 || this.prePosition == 0)
                {
                }
                else
                {
                    myBook.AnimateToPreviousPage(this.albumsCollectionView.CurrentPosition == 0, 700);
                }
            }
            else
            {
                if (this.prePosition % 2 == 0 || this.prePosition == 0)
                {
                    myBook.AnimateToNextPage(this.albumsCollectionView.CurrentPosition == 0, 700);
                }
            }
        }

        #endregion
    }
}
